package com.hsy.baoinbao.modules.notice.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.deparse.dpframe.utils.DPHttpUtil;
import com.hsy.baoinbao.R;
import com.hsy.baoinbao.common.Consts;
import com.hsy.baoinbao.modules.common.CommonBaseActivityWithSimpleActionBar;
import com.hsy.baoinbao.utils.CommonUtils;
import com.hsy.baoinbao.utils.HttpUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class DetailNoticeActivity extends CommonBaseActivityWithSimpleActionBar {
    private TextView person_about_us_name, person_about_us_content, person_about_us_date;
    private DPHttpUtil.HttpCallback callback = new DPHttpUtil.HttpCallback() {
        @Override
        public void onSuccess(int what, String response) {
            if (0 == what) {
                try {
                    JSONObject result = new JSONObject(response);
                    String id = result.optString("id");
                    String date = result.optString("date");
                    String name = result.optString("name");
                    String context = result.optString("context");
                    person_about_us_name.setText(name);
                    person_about_us_content.setText(context);
                    person_about_us_date.setText(date);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                CommonUtils.hideProgressDialog();
            }
        }

        @Override
        public void onError(int what, int type, VolleyError error) {
            if (0 == what) {
                CommonUtils.hideProgressDialog();
            }
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.detail_notic);
        setTitle("详情");
        Intent intent = getIntent();
        person_about_us_name = F(R.id.person_about_us_name);
        person_about_us_content = F(R.id.person_about_us_content);
        person_about_us_date = F(R.id.person_about_us_date);

        CommonUtils.showProgressDialog(this);
        Map<String, String> params = new HashMap<>();
        params.put(Consts.TOKEN, CommonUtils.getToken(this));
        params.put("id", intent.getStringExtra("id"));
        HttpUtil.httpPostWithParams(this, 0, Consts.API_GET_NOTICE_DETAIL, params, callback);
    }
}
